package com.overkill.game;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;

public class Renderable {
	
	private int width;
	private int height;
	
	private PointF position = new PointF(0, 0);
	
	private boolean visible = true;
	private boolean presist = false;
	
	private RectF relativHitBox = null;
	
	public boolean wasHit = false;
	
	public Renderable() {
	}

	/**
	 * Moves the Object by a given value
	 * 
	 * @param xBy
	 *            Pixels to move along the X-Axis
	 * @param yBy
	 *            Pixels to move along the Y-Axis
	 */
	public void moveBy(float xBy, float yBy) {
		moveTo(this.position.x + xBy, this.position.y + yBy);
	}
	
	public void moveXBy(float xBy){
		moveTo(this.position.x + xBy, this.position.y);
	}
	
	public void moveYBy(float yBy){
		moveTo(this.position.x, this.position.y + yBy);
	}

	/**
	 * Moves Object to a position
	 * 
	 * @param x
	 *            The X-Axis position to move to
	 * @param y
	 *            The Y-Axis position to move to
	 */
	public void moveTo(float x, float y) {
		this.position.x = x;
		this.position.y = y;
	}

	public void moveX(float f) {
		this.moveTo(f, position.y);
	}

	public void moveY(float y) {
		this.moveTo(position.x, y);
	}

	public void update(long gameTime) {
		
	}

	public void draw(Canvas canvas) {
		
	}
	
	public void draw(Canvas canvas, Paint paint) {
		
	}

	public PointF getPosition() {
		return position;
	}

	public void setPosition(PointF position) {
		this.position = position;
	}

	public RectF getFrame() {
		return new RectF(position.x, position.y, position.x
				+ getWidth(), position.y
				+ getHeight());
	}


	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public void setPresist(boolean presist) {
		this.presist = presist;
	}

	public boolean isPresist() {
		return presist;
	}

	public void setRelativHitBox(RectF relativeHitBox) {
		this.relativHitBox = relativeHitBox;
	}

	public RectF getRelativHitBox() {
		return relativHitBox;
	}
	
	public RectF getAbsolutHitBox() {
		if(relativHitBox == null){
			return getFrame();
		}else{
			return new RectF(
					getPosition().x + this.relativHitBox.left, 
					getPosition().y + this.relativHitBox.top, 
					getPosition().x + this.relativHitBox.right, 
					getPosition().y + this.relativHitBox.bottom);
		}
	}

	public boolean isHit(Renderable r){
		return RectF.intersects(getAbsolutHitBox(), r.getFrame());
	}
	
	public boolean isHit(float x, float y){
		return getAbsolutHitBox().contains(x, y);
	}
	
	public boolean isHit(PointF p){
		return this.isHit(p.x, p.y);
	}
	
	public int getWidth(){
		return width;
	}
	
	public void setWidth(int width) {
		this.width = width;
	}
	
	public int getHeight(){
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
}